//
//  ST_PaySuccessController.swift
//  btvideo
//
//  Created by mac on 2020/5/9.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SnapKit
import SwifterSwift

class ST_PaySuccessController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = .clear
        
        view.addSubview(success_root_view)
        success_root_view.snp.makeConstraints { (make) in
            make.width.equalTo(320)
            make.height.equalTo(420)
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview()
        }
        
        success_root_view.addSubview(success_title_btn)
        success_title_btn.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(33)
            make.width.equalTo(170)
            make.height.equalTo(30)
        }
        
        success_root_view.addSubview(success_center_image_view)
        success_center_image_view.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(success_title_btn.snp.bottom).offset(14)
            make.width.equalTo(180)
            make.height.equalTo(120)
        }
        
        success_root_view.addSubview(success_center_label)
        success_center_label.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(success_center_image_view.snp.bottom).offset(27)
        }
        
        success_root_view.addSubview(success_center_sub_label)
        success_center_sub_label.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(success_center_label.snp.bottom).offset(5)
        }
        
        
        success_root_view.addSubview(success_ok_btn)
        success_ok_btn.snp.makeConstraints { (make) in
            make.width.equalTo(260)
            make.height.equalTo(36)
            make.centerX.equalToSuperview()
            make.top.equalTo(success_center_sub_label.snp.bottom).offset(44)
        }
        
    }
    
    fileprivate lazy var success_root_view:UIView = {
       let control = UIView()
        control.cornerRadius = 20
        control.backgroundColor = Color.white
        return control
    }()
    
    fileprivate lazy var success_title_btn:UIButton = {
            
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        
        
        control.setTitleForAllStates("支付成功")
        
        control.setTitleColorForAllStates(UIColor.init(hexString: "#333333")!)
        
        control.titleLabel?.font = UIFont.systemFont(ofSize: 20, weight: UIFont.Weight.semibold)
        
        control.semanticContentAttribute = .forceRightToLeft
        
        control.imageEdgeInsets = UIEdgeInsets.init(top: 0, left: 5, bottom: 0, right: 0)
        
        return control
    }()
    
    fileprivate lazy var success_center_image_view:UIImageView = {
        let control = UIImageView()
        control.image = ST_ImageUtils.imageName("首页_img_支付成功")
        return control
    }()

    fileprivate lazy var success_center_label:UILabel = {
        let label = UILabel()
        let attrString = NSMutableAttributedString(string: "真棒！支付成功！")
        let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.medium),.foregroundColor: UIColor.init(hexString: "#333333")!]
        attrString.addAttributes(attr, range: NSRange(location: 0, length: attrString.length))
        label.attributedText = attrString
        return label
    }()
    
    
    fileprivate lazy var success_center_sub_label:UILabel = {
        let label = UILabel()
        let attrString = NSMutableAttributedString(string: "开始尽情地玩耍吧~")
        let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.regular),.foregroundColor: UIColor.init(hex: 0x666666)!]
        attrString.addAttributes(attr, range: NSRange(location: 0, length: attrString.length))
        label.attributedText = attrString
        return label
    }()
    
    fileprivate lazy var success_ok_btn:UIButton = {
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.setTitleForAllStates("好的")
        control.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.semibold)
        control.setTitleColorForAllStates(UIColor.white)
        control.backgroundColor = Color.init(hexString: "#FEC207")
        control.cornerRadius = 18
        control.add_touch_up(insideTarget: self, action: #selector(cancel_handle))
        return control
    }()
    
//    MARK: - Event
    
    var close_closure:(()->())?
    
    @objc func cancel_handle(){
        
        
        goback_previous_controller(animated: true) {
            self.close_closure?()
        }
        
    }

}







//MARK: - 通用 支付成功 新版

class GlobalST_PaySuccessController: UIViewController {
    
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
         super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
     }
     
    @objc public convenience init(title:String,message:String,imageName:String,confirmText:String = "好的") {
     
         self.init(nibName: nil, bundle: nil)
         
        success_center_image_view.image = UIImage.init(named: imageName)
        
        successTitleLabel.text = title
        
        let attrStr = NSMutableAttributedString.init(string: message)
        
        attrStr.addAttributes(successCenterLabelAttr, range: NSRange.init(location: 0, length: attrStr.length))
        
        success_center_label.attributedText = attrStr
        
        success_ok_btn.setTitleForAllStates(confirmText)
     }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = .clear
        
        view.addSubview(success_root_view)
        success_root_view.snp.makeConstraints { (make) in
            make.width.equalTo(300)
            make.height.equalTo(320)
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview()
        }
        
        success_root_view.addSubview(success_center_image_view)
        success_center_image_view.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(20)
            make.width.equalTo(202)
            make.height.equalTo(119)
        }
        
        success_root_view.addSubview(successTitleLabel)
        successTitleLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(success_center_image_view.snp.bottom).offset(21)
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.height.equalTo(25)
        }
        
        
        
        success_root_view.addSubview(success_center_label)
        success_center_label.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(successTitleLabel.snp.bottom).offset(6)
        }
        
        
        success_root_view.addSubview(success_ok_btn)
        success_ok_btn.snp.makeConstraints { (make) in
            make.width.equalTo(200)
            make.height.equalTo(44)
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-20)
        }
        
    }
    
    fileprivate lazy var success_root_view:UIView = {
       let control = UIView()
        control.cornerRadius = 20
        control.backgroundColor = Color.white
        return control
    }()
    
    fileprivate lazy var successTitleLabel:UILabel = {
            
        let control = UILabel()
        
        control.textColor = UIColor.init(hex: 0x333333)
        
        control.textAlignment = .center
        
        control.font = UIFont.systemFont(ofSize: 18, weight: UIFont.Weight.medium)
        
        return control
    }()
    
    fileprivate lazy var success_center_image_view:UIImageView = {
        let control = UIImageView()
        return control
    }()

    fileprivate lazy var successCenterLabelAttr:[NSAttributedString.Key : Any] = {
        
        let p = NSParagraphStyle.create_line_spacing_paragraph_style(lineSpacing: 3)
        
        p.alignment = .center
        
        let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.regular),.foregroundColor: UIColor.init(hexString: "#61666F")!,.paragraphStyle:p]
        
        return attr
    }()
    
    fileprivate lazy var success_center_label:UILabel = {
        let label = UILabel()
        label.numberOfLines = 0
        return label
    }()
    
    fileprivate lazy var success_ok_btn:UIButton = {
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.semibold)
        control.setTitleColorForAllStates(UIColor.white)
        control.backgroundColor = Color.init(hexString: "#FEC207")
        control.cornerRadius = 18
        control.add_touch_up(insideTarget: self, action: #selector(cancel_handle))
        return control
    }()
    
//    MARK: - Event
    
    var close_closure:(()->())?
    
    @objc func cancel_handle(){
        
        
        goback_previous_controller(animated: true) {
            self.close_closure?()
        }
        
    }

}
